//
//  THJAllPayVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/8/11.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJAllPayVC.h"

@interface THJAllPayVC ()

@end

@implementation THJAllPayVC

- (void)viewDidLoad {
    [super viewDidLoad];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"全额支付"];
    }else{
         [self setNavBarWithTitle:@"全额支付"];
    }
    [self getData];
    self.tf.secureTextEntry = YES;
    // Do any additional setup after loading the view from its nib.
}

-(void)getData{
    [self SVHUDShow];
    NSString * itemid = [RSA encryptString:self.itemid publicKey:RSA_PubKey];
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=buyer_confirm_order" parameters:@{@"itemid":itemid,@"type":@"ios"} callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"全额支付--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            self.lab1.text = [RSA decryptString:receiveData[@"data"][@"yMoney"] publicKey:RSA_PubKey];
            self.lab2.text = [RSA decryptString:receiveData[@"data"][@"buyer_accnm"] publicKey:RSA_PubKey];
            self.lab3.text = [RSA decryptString:receiveData[@"data"][@"seller_accnm"] publicKey:RSA_PubKey];
            self.lab4.text = [RSA decryptString:receiveData[@"data"][@"seller_accno"] publicKey:RSA_PubKey];
            self.lab5.text = [RSA decryptString:receiveData[@"data"][@"amount"] publicKey:RSA_PubKey];
        }else{
            [self HUDShowMsg:@"获取信息失败" AfterDelayDimiss:1];
        }
        
    }];
}

- (IBAction)sureBtnAction:(id)sender {
    
    if(self.tf.text.length == 0){
        [self HUDShowMsg:@"请输入支付密码" AfterDelayDimiss:1];
    }else{
        [self SVHUDShow];
        NSString * mobile = [RSA encryptString:[THJTools getMobile] publicKey:RSA_PubKey];
        NSString * itemid = [RSA encryptString:self.itemid publicKey:RSA_PubKey];
        NSString * pwd = [RSA encryptString:self.tf.text publicKey:RSA_PubKey];
        NSDictionary * dic = @{
                               @"type":@"ios",
                               @"mobile":mobile,
                               @"itemid":itemid,
                               @"pwd":pwd
                               };
        [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=buyer_gotopay" parameters:dic callback:^(NSDictionary *  receiveData, NSError *error) {
            NSLog(@"全额支付--%@--%@",receiveData,[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey]);
            [self SVHUDHiden];
            if([receiveData[@"status"] isEqual:@"success"]){
                [self HUDShowMsg:@"支付成功" AfterDelayDimiss:1];
                [self getData];
                [[NSNotificationCenter defaultCenter] postNotificationName:@"paySuccess" object:nil userInfo:nil];
                [self performSelector:@selector(popAction) withObject:nil afterDelay:1];
            }else{
                [self HUDShowMsg:[RSA decryptString:receiveData[@"data"] publicKey:RSA_PubKey] AfterDelayDimiss:1];
            }
        }];
    }
}
-(void)popAction{
    [self.navigationController popViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
